package day20180408;

import java.sql.*;

public class oneKeyTest3 {

    public static void main(String[] args) {

        //3+1从数据库获取数据
        Connection connection = null;
        Statement statement = null;
        ResultSet resultset = null;

        //查询数据库，照成绩排序
        String sql = "select * from t_exam order by lqzydm";

        try {
            Class.forName("com.mysql.jdbc.Driver");

            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/sctu?serverTimezone = UTC",
                    "root",
                    "123456"
            );


            statement = connection.createStatement();
            resultset = statement.executeQuery(sql);

            while(resultset.next()) {

                int id = resultset.getInt(1);
                String sname = resultset.getString(2);
                int sex = resultset.getInt(3);
                String lqzydm = resultset.getString(4);
                int cj = resultset.getInt(5);

                System.out.println("ID:" + id + "\t" + "姓名:" + sname + "\t" + "录取专业代码:" + lqzydm);

            }

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }

}
